import axios from 'axios'

const request = axios.create({
	timeout: 5000
})

request.interceptors.request.use((config) => {
	// 挂载请求头token
	config.headers.token = 'QRWLEKJRKQWALFKENRKKQWEDWSEFWEWERWExxxx'

	return config
}, (error) => {
	return Promise.reject(error)
})


request.interceptors.response.use((response) => {
	const { code } = response.data

	if(code === '500') {
		console.log('服务器报错');
	}

	if(code === 400) {
		console.log('请求客户端问题');
	}

	if(code === 404) {
		console.log('资源没有找到');
	}

	return response

}, (error) => {
	return Promise.reject(error)
})

export default request